import 'package:flutter/material.dart';
import 'package:flutter_mall/pages/tabbar/goods.dart';
import 'package:flutter_mall/pages/tabbar/home.dart';
import 'package:flutter_mall/pages/tabbar/user.dart';

class Index extends StatefulWidget {
  @override
  _IndexState createState() => _IndexState();
}

class _IndexState extends State<Index>{

  final List<BottomNavigationBarItem> _tabbar = [
    BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('首页')),
    BottomNavigationBarItem(icon: Icon(Icons.search), title: Text('分类')),
    BottomNavigationBarItem(icon: Icon(Icons.people), title: Text('我的'))
  ];

  final List<Widget> _tabbarPage = [
    Home(),
    Goods(),
    User()
  ];

  int _cur = 0; //tabbar当前索引
  void _switchTabbar(int e) {
    setState(() {
      _cur = e;
    });
  }

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        items: _tabbar,
        currentIndex: _cur,
        onTap: _switchTabbar,
      ),
      body: IndexedStack(
        index: _cur,
        children: _tabbarPage,
      ),
    );
  }
}